#!/usr/bin/env bash

if [[ "${TRAVIS_OS_NAME:-}" == "linux" ]]; then
  pyenv global 3.7.1
fi

pip3 install --user wheel jupyter jupyter_kernel_test

if [ "${METHOD:-}" = "ros" ]; then
  curl -L https://raw.githubusercontent.com/snmsts/roswell/release/scripts/install-for-ci.sh | sh
  ros config
  ros install yitzchak/cl-indentify
  ros install ./common-lisp-jupyter.asd
  ros run --eval "(ql:quickload '(:common-lisp-jupyter :jsown))" --quit
else
  git clone https://github.com/yitzchak/cl-indentify.git ~/quicklisp/local-projects/cl-indentify

  if [ "${METHOD:-}" != "img" ]; then
    mkdir -p ~/quicklisp/local-projects/
    curl -LO https://github.com/yitzchak/ziz/archive/master.zip
    unzip master.zip -d ~/quicklisp/local-projects/
    rm master.zip
  fi

  curl -kLO https://beta.quicklisp.org/quicklisp.lisp

  if [ "$LISP" = "clisp" ]; then
    clisp scripts/$METHOD-install.lisp
  elif [ "$LISP" = "ecl" ]; then
    ecl -shell scripts/$METHOD-install.lisp
  else
    $LISP --load scripts/$METHOD-install.lisp --quit
  fi

  if [ "${METHOD:-}" = "loc" ] || [ "${METHOD:-}" = "sys" ]; then
    sudo cp -r ./pkg/* /
    echo "(uiop:quit)" | jupyter-console --no-confirm-exit --kernel=common-lisp --ZMQTerminalInteractiveShell.kernel_timeout=240
  fi
fi
